package com.yimi.yinhepda.adapter.RecycleAdapter;

import android.content.Context;
import android.view.View;
import android.widget.RadioButton;


import com.yimi.yinhepda.R;
import com.pda.ym.base.CommonRecycleAdapter;
import com.pda.ym.base.CommonViewHolder;
import com.yimi.yinhepda.entity.response.UnBlockingResponse;


import java.util.List;

/**
 * Created by msa1111 on 2018/6/7.
 */

public class UnBlockingAdapter extends CommonRecycleAdapter<UnBlockingResponse.BarBillTaskEntity> {


    private Context mContext;

    private CommonViewHolder.onItemCommonClickListener mCommonClickListener;
    /**
     * 1.解封车 2.封车卸车
     */
    private int type;
    /**
     * 1-左布局，2-右布局
     */
    private int layoutType;

    public UnBlockingAdapter(Context context, List<UnBlockingResponse.BarBillTaskEntity> dataList, int layoutId, CommonViewHolder.onItemCommonClickListener mCommonClickListener, int type, int layoutType) {
        super(context, dataList, layoutId);
        this.mContext = context;
        this.mCommonClickListener = mCommonClickListener;
        this.type = type;
        this.layoutType = layoutType;
    }


    @Override
    public void bindData(CommonViewHolder holder, UnBlockingResponse.BarBillTaskEntity data, int position) {
        if (layoutType == 1) {
            //左布局
            if (!data.getStowageNo().startsWith("P")) {
                //快递展示车标号
                holder.setText(R.id.tv_stowageNo, data.getCarMark());
            } else {
                holder.setText(R.id.tv_stowageNo, data.getStowageNo());
            }
        } else {
            //右布局
            holder.setText(R.id.tv_carNo, data.getCarNo());
            holder.setText(R.id.tv_taskno,
                    data.getTaskNo() == null ? "" :
                            data.getTaskNo().substring(data.getTaskNo().length() - 5, data.getTaskNo().length()));
            holder.setText(R.id.tv_dest_dept, data.getDestDeptName());
            if (type == 1) {
                holder.setText(R.id.item_time, data.getScheduleNo());
            } else {
                holder.setText(R.id.item_time, getSealStatus(data.getSealStatus()));
            }
            RadioButton rb = holder.getView(R.id.rb_check);
            rb.setChecked(data.isCheck());
        }
        holder.setCommonClickListener(mCommonClickListener);
        View view = holder.itemView;
        if (data.isCheck()) {
            view.setBackgroundColor(mContext.getResources().getColor(R.color.green));
        } else {
            view.setBackgroundColor(mContext.getResources().getColor(R.color.white));
        }
    }

    private CharSequence getBizType(int bizTypeCode) {
        String[] lineTypeArr = mContext.getResources().getStringArray(R.array.line_type);
        return lineTypeArr[bizTypeCode];
    }

    private String getSealStatus(int sealStatus) {
        //   1未绑定 2已绑定 3已解封 4封签遗失 5封签破损 6封签漏扫 7封签错误
        String[] sealStatusArr = mContext.getResources().getStringArray(R.array.seal_status);

        return sealStatusArr[sealStatus];

    }
}
